home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / gucrtr13.lha / GUICreator1.3 / GUIC.lha / GUICreator / Demos / ManageCDPics_Functions.c < prev    next >
C/C++ Source or Header  |  1995-08-22  |  14KB  |  339 lines

  1. /*************************************************************************/
  2. /*                                                                       */
  3. /*   Includes                                                            */
  4. /*                                                                       */
  5. /*************************************************************************/
  6.  
  7. #include "ManageCDPics_Includes.h"
  8. #include "ManageCDPics_Structures.h"
  9.  
  10. /*************************************************************************/
  11. /*                                                                       */
  12. /*   Variables and Structures                                            */
  13. /*                                                                       */
  14. /*************************************************************************/
  15.  
  16. extern struct IntuitionBase  *IntuitionBase;
  17. extern struct GfxBase        *GfxBase;
  18.  
  19. extern struct Library *GadToolsBase;
  20. extern struct Library *AslBase;
  21. extern struct Library *DataTypesBase;
  22.  
  23. /*************************************************************************/
  24. /*                                                                       */
  25. /*   Defines                                                             */
  26. /*                                                                       */
  27. /*************************************************************************/
  28.  
  29. #define RASTERX (GfxBase->DefaultFont->tf_XSize)
  30. #define RASTERY (GfxBase->DefaultFont->tf_YSize)
  31.  
  32. #define XSIZE(x)  ((x)*RASTERX)
  33. #define YSIZE(x)  ((x)*RASTERY)
  34.  
  35. #define XPOS(x)   (XSIZE(x)+customscreen->WBorLeft)
  36. #define YPOS(x)   (YSIZE(x)+customscreen->BarHeight+1)
  37.  
  38. /*************************************************************************/
  39. /*                                                                       */
  40. /*   SleepWindow() und WakenWindow()                                     */
  41. /*                                                                       */
  42. /*************************************************************************/
  43.  
  44. static struct Requester waitrequest;
  45.  
  46. void SleepWindow(struct Window *win)
  47. {
  48.     InitRequester(&waitrequest);
  49.     if (win->FirstRequest == NULL ) Request(&waitrequest,win);
  50.     SetWindowPointer(win,WA_BusyPointer,1L,TAG_DONE);
  51. }
  52.  
  53. void WakenWindow(struct Window *win)
  54. {
  55.     if (win->FirstRequest != NULL) EndRequest(&waitrequest,win);
  56.     SetWindowPointer(win,WA_Pointer,0L,TAG_DONE);
  57. }
  58.  
  59. /*************************************************************************/
  60. /*                                                                       */
  61. /*   GUIC_ErrorReport()                                             */
  62. /*                                                                       */
  63. /*************************************************************************/
  64.  
  65. void GUIC_ErrorReport(struct Window *win,ULONG type)
  66. {
  67.     char error[256];
  68.     struct EasyStruct easystruct = { sizeof(struct EasyStruct),0,"Caution:",error,"OK" };
  69.  
  70.     if (type == ERROR_NO_WINDOW_OPENED)
  71.         strcpy(error,"Could not open window (no memory?)");
  72.     else if (type == ERROR_NO_PUBSCREEN_LOCKED)
  73.         strcpy(error,"Could not lock pubscreen");
  74.     else if (type == ERROR_NO_GADGETS_CREATED)
  75.         strcpy(error,"Could not create gadgets");
  76.     else if (type == ERROR_NO_GADGETLIST_CREATED)
  77.         strcpy(error,"Could not create gadgetlist");
  78.     else if (type == ERROR_NO_VISUALINFO)
  79.         strcpy(error,"Could not read visualinfo from screen");
  80.     else if (type == ERROR_NO_PICTURE_LOADED)
  81.         strcpy(error,"Could not read picture data");
  82.     else if (type == ERROR_NO_WINDOW_MENU)
  83.         strcpy(error,"Could not create menu");
  84.     else if (type == ERROR_SCREEN_TOO_SMALL)
  85.         strcpy(error,"This screen is too small for the window");
  86.     else if (type == ERROR_LIST_NOT_INITIALIZED)
  87.         strcpy(error,"The attached list is not initialized!");
  88.     else Fault(type,"Error",error,sizeof(error));
  89.  
  90.     if (win && !win->FirstRequest)
  91.         {
  92.         SleepWindow(win);
  93.         EasyRequestArgs(win,&easystruct,NULL,NULL);
  94.         WakenWindow(win);
  95.         }
  96.     else EasyRequestArgs(win,&easystruct,NULL,NULL);
  97.  
  98. }
  99.  
  100. /*************************************************************************/
  101. /*                                                                       */
  102. /*   CreateBevelFrames()                                                 */
  103. /*                                                                       */
  104. /*************************************************************************/
  105.  
  106. void CreateBevelFrames(struct Window *win,APTR visualinfo,ULONG bevelcount,struct BevelFrame bevels[])
  107. {
  108.     ULONG i;
  109.     for (i=0;i<bevelcount;i++)
  110.         {
  111.         DrawBevelBox(win->RPort,bevels[i].bb_LeftEdge,bevels[i].bb_TopEdge,bevels[i].bb_Width,bevels[i].bb_Height,GT_VisualInfo,visualinfo,GTBB_Recessed,TRUE,TAG_END);
  112.         DrawBevelBox(win->RPort,bevels[i].bb_LeftEdge+2,bevels[i].bb_TopEdge+1,bevels[i].bb_Width-4,bevels[i].bb_Height-2,GT_VisualInfo,visualinfo,TAG_END);
  113.         if (bevels[i].bb_Title)
  114.             {
  115.             char title[64];
  116.             sprintf(title," %s ",bevels[i].bb_Title);
  117.             Move(win->RPort,bevels[i].bb_LeftEdge+(bevels[i].bb_Width-XSIZE(strlen(title)))/2,bevels[i].bb_TopEdge+2);
  118.             SetAPen(win->RPort,bevels[i].bb_Color);
  119.             Text(win->RPort,title,strlen(title));
  120.             }
  121.         /* end-if */
  122.         }
  123.     /* end-for */
  124. }
  125.  
  126. /*************************************************************************/
  127. /*                                                                       */
  128. /*   CreateLines()                                                       */
  129. /*                                                                       */
  130. /*************************************************************************/
  131.  
  132. void CreateLines(struct Window *win,int linecount,struct Line lines[])
  133. {
  134.     ULONG i;
  135.     for (i=0;i<linecount;i++)
  136.         {
  137.         SetAPen(win->RPort,lines[i].li_Color);
  138.         Move(win->RPort,lines[i].li_LeftEdge,lines[i].li_TopEdge);
  139.         Draw(win->RPort,lines[i].li_Width>0?lines[i].li_LeftEdge+lines[i].li_Width-1:lines[i].li_LeftEdge+lines[i].li_Width,lines[i].li_Height>0?lines[i].li_TopEdge+lines[i].li_Height-1:lines[i].li_TopEdge+lines[i].li_Height);
  140.         }
  141.     /* end-for */
  142. }
  143.  
  144. /*************************************************************************/
  145. /*                                                                       */
  146. /*   CreateTexts()                                                       */
  147. /*                                                                       */
  148. /*************************************************************************/
  149.  
  150. void CreateTexts(struct Window *win,int textcount,struct Text texts[], long double xscale,long double yscale)
  151. {
  152.     ULONG i;
  153.     for (i=0;i<textcount;i++)
  154.         {
  155.         SetAPen(win->RPort,texts[i].tx_Color);
  156.         Move(win->RPort,texts[i].tx_LeftEdge,texts[i].tx_TopEdge+(ULONG)(yscale*GfxBase->DefaultFont->tf_Baseline));
  157.         Text(win->RPort,texts[i].tx_Text,strlen(texts[i].tx_Text));
  158.         }
  159.     /* end-for */
  160. }
  161.  
  162. /*************************************************************************/
  163. /*                                                                       */
  164. /*   ShowGadget()                                                        */
  165. /*                                                                       */
  166. /*************************************************************************/
  167.  
  168. #define GADGET_DOWN  0
  169. #define GADGET_UP    1
  170.  
  171. void ShowGadget(struct Window *win, struct Gadget *gad, int type)
  172. {
  173.     if ((gad->Flags & GFLG_DISABLED) == 0)
  174.         {
  175.         int gadpos = RemoveGadget(win, gad);
  176.  
  177.         if (type == GADGET_DOWN)
  178.             gad->Flags |= GFLG_SELECTED;
  179.         else
  180.             gad->Flags &= ~GFLG_SELECTED;
  181.  
  182.         AddGadget(win, gad, gadpos);
  183.         RefreshGList(gad, win, NULL, 1);
  184.     }
  185. }
  186.  
  187. /*************************************************************************/
  188. /*                                                                       */
  189. /*   About()                                                             */
  190. /*                                                                       */
  191. /*************************************************************************/
  192.  
  193. void About(struct Window *hostwin,struct Gadget **wingads,APTR userdata)
  194. {
  195.     APTR visualinfo=GetVisualInfo(hostwin->WScreen,TAG_DONE);
  196.     if (visualinfo)
  197.         {
  198.         Object *o=NewDTObject("/About.IFF",DTA_SourceType,DTST_FILE,DTA_GroupID,GID_PICTURE,TAG_DONE);
  199.         if (o)
  200.             {
  201.             struct Gadget  *gadgetlist   = NULL;
  202.             struct Screen  *customscreen = hostwin->WScreen;
  203.             struct Gadget  *gadget       = CreateContext(&gadgetlist);
  204.             if (gadget)
  205.                 {
  206.                 ULONG height=25,width=34,left=0,top=0;
  207.                 ULONG textcount=18;
  208.  
  209.                 struct Gadget *wingad;
  210.  
  211.                 char * title                  = "About";
  212.                 struct Window     *win        = NULL;
  213.  
  214.                 struct TextAttr   textattr    = { GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name,GfxBase->DefaultFont->tf_YSize,FS_NORMAL,FPF_DISKFONT };
  215.  
  216.                 struct NewGadget  newgad      = { XPOS(1),YPOS(22),XSIZE(32)+200,YSIZE(2),"_OK",&textattr,2,PLACETEXT_IN,visualinfo,NULL };
  217.  
  218.                 struct Text       texts[]     = {
  219.                                                              200+XPOS(4),YPOS(2),"****************************",1,
  220.                                                              200+XPOS(4),YPOS(3),"*                          *",1,
  221.                                                              200+XPOS(4),YPOS(4),"*  This  GUI was designed  *",1,
  222.                                                              200+XPOS(4),YPOS(5),"*                          *",1,
  223.                                                              200+XPOS(4),YPOS(6),"*  with GUI-Creator V 1.0  *",1,
  224.                                                              200+XPOS(4),YPOS(7),"*                          *",1,
  225.                                                              200+XPOS(4),YPOS(8),"*  © 1995 by               *",1,
  226.                                                              200+XPOS(4),YPOS(9),"*  Markus Hillenbrand      *",1,
  227.                                                              200+XPOS(4),YPOS(10),"*                          *",1,
  228.                                                              200+XPOS(4),YPOS(11),"* ------------------------ *",1,
  229.                                                              200+XPOS(4),YPOS(12),"*                          *",1,
  230.                                                              200+XPOS(4),YPOS(13),"* GUI-Creator is Shareware *",1,
  231.                                                              200+XPOS(4),YPOS(14),"*                          *",1,
  232.                                                              200+XPOS(4),YPOS(15),"* Please read the docs for *",1,
  233.                                                              200+XPOS(4),YPOS(16),"*                          *",1,
  234.                                                              200+XPOS(4),YPOS(17),"* more information!        *",1,
  235.                                                              200+XPOS(4),YPOS(18),"*                          *",1,
  236.                                                              200+XPOS(4),YPOS(19),"****************************",1,
  237.                                                              };
  238.  
  239.                 height= YSIZE(height);
  240.                 width = XSIZE(width)+200;
  241.                 left  = (customscreen->Width-width)/2;
  242.                 top   = (customscreen->Height-height)/2;
  243.  
  244.                 wingad = gadget = CreateGadget(BUTTON_KIND,gadget,&newgad,GT_Underscore,'_',TAG_END);
  245.  
  246.                 if (height>customscreen->Height || width>customscreen->Width) GUIC_ErrorReport(hostwin,ERROR_SCREEN_TOO_SMALL);
  247.                 win=OpenWindowTags(NULL,WA_Activate,         TRUE,
  248.                                                 WA_CloseGadget,      TRUE,
  249.                                                 WA_DepthGadget,      TRUE,
  250.                                                 WA_SizeGadget,       FALSE,
  251.                                                 WA_DragBar,          TRUE,
  252.                                                 WA_Gadgets,          gadgetlist,
  253.                                                 WA_InnerHeight,      height,
  254.                                                 WA_InnerWidth,       width,
  255.                                                 WA_IDCMP,            IDCMP_CLOSEWINDOW|BUTTONIDCMP|IDCMPUPDATE|IDCMP_VANILLAKEY,
  256.                                                 WA_Left,             left,
  257.                                                 WA_Top,              top,
  258.                                                 WA_SmartRefresh,     TRUE,
  259.                                                 WA_Title,            title,
  260.                                                 WA_CustomScreen,     customscreen,
  261.                                                 TAG_END);
  262.                 if (win)
  263.                     {
  264.                     struct IntuiMessage  *imessage   = NULL;
  265.                     struct Gadget        *idcmpgad   = NULL;
  266.                     struct BitMap        *bmcopy     = NULL;
  267.                     struct TagItem       *tag        = NULL;
  268.                     struct TagItem       *tstate     = NULL;
  269.                     ULONG  idcmpclass                = 0;
  270.                     UWORD  messagecode               = 0;
  271.                     BOOL   running                   = TRUE;
  272.  
  273.                     SleepWindow(hostwin);
  274.                     SetFont(win->RPort,GfxBase->DefaultFont);
  275.  
  276.                     DrawBevelBox(win->RPort,XPOS(1),YPOS(1),204,102,GT_VisualInfo,visualinfo,GTBB_Recessed,TRUE,TAG_END);
  277.                     DrawBevelBox(win->RPort,XPOS(3)+200,YPOS(1),XSIZE(30),YSIZE(20),GT_VisualInfo,visualinfo,GTBB_Recessed,TRUE,TAG_END);
  278.  
  279.                     SetDTAttrs(o,NULL,NULL,GA_Left,XPOS(1)+2,GA_Top,YPOS(1)+1,GA_Width,200,GA_Height,100,PDTA_Remap,TRUE,PDTA_DestBitMap,&bmcopy,ICA_TARGET,ICTARGET_IDCMP,TAG_DONE);
  280.                     AddDTObject(win,NULL,o,-1L);
  281.  
  282.                     CreateTexts(win,textcount,texts,1.0,1.0);
  283.  
  284.                     GT_RefreshWindow(win,NULL);
  285.  
  286.                     while (running)
  287.                         {
  288.                         Wait(1L << win->UserPort->mp_SigBit);
  289.                         while (imessage=GT_GetIMsg(win->UserPort))
  290.                             {
  291.                             idcmpgad=(struct Gadget *)imessage->IAddress;
  292.                             idcmpclass=imessage->Class;
  293.                             messagecode =imessage->Code;
  294.  
  295.                             GT_ReplyIMsg(imessage);
  296.  
  297.                             switch(idcmpclass)
  298.                                 {
  299.                                 case IDCMP_VANILLAKEY:
  300.                                     if (messagecode == 27 || messagecode == 'o' || messagecode == 'O') running=FALSE;
  301.                                     break;
  302.                                 case IDCMP_REFRESHWINDOW:
  303.                                     GT_BeginRefresh(win);
  304.                                     GT_EndRefresh(win,TRUE);
  305.                                     break;
  306.                                 case IDCMP_CLOSEWINDOW:
  307.                                     running=FALSE;
  308.                                     break;
  309.                                 case BUTTONIDCMP:
  310.                                     running=FALSE;
  311.                                     break;
  312.                                 case IDCMP_IDCMPUPDATE:
  313.                                     tstate=(struct TagItem*)imessage->IAddress;
  314.                                     while (tag=NextTagItem(&tstate)) if (tag->ti_Tag == DTA_Sync) RefreshDTObjectA(o,win,NULL,NULL);
  315.                                     break;
  316.                                 }
  317.                             /* end-switch */
  318.  
  319.                             }
  320.                         /* end-while */
  321.                         }
  322.                     /* end-while */
  323.  
  324.                     CloseWindow(win);
  325.                     WakenWindow(hostwin);
  326.                     }
  327.                 else GUIC_ErrorReport(hostwin,ERROR_NO_WINDOW_OPENED);
  328.                 FreeGadgets(gadgetlist);
  329.                 }
  330.             else GUIC_ErrorReport(hostwin,ERROR_NO_GADGETLIST_CREATED);
  331.             DisposeDTObject(o);
  332.             }
  333.         else GUIC_ErrorReport(hostwin,ERROR_NO_PICTURE_LOADED);
  334.         FreeVisualInfo(visualinfo);
  335.         }
  336.     else GUIC_ErrorReport(hostwin,ERROR_NO_VISUALINFO);
  337.  
  338. }
  339.